#pragma once
#include "Singleton.h"
#include <functional>
#include <map>
#include <string>


class HttpConnection;

class LogicSystem:public Singleton<LogicSystem>
{

    using HttpHandler = std::function<void (std::shared_ptr<HttpConnection>)>;
    friend class Singleton<LogicSystem>;
public:
    ~LogicSystem()=default;
    //注册GET请求处理函数
    void RegGet(std::string url,HttpHandler handler);
    //处理GET请求
    bool HandleGet(std::string url,std::shared_ptr<HttpConnection> conn);



    //注册POST请求处理函数
    void RegPost(std::string url,HttpHandler handler);
    //处理POST请求
    bool HandlePost(std::string url,std::shared_ptr<HttpConnection> conn);



private:
    LogicSystem();


    /**
     * @brief 以下为POST请求处理函数
     * 
     */
    void GetVerifyCodeHandler(std::shared_ptr<HttpConnection> conn);
    void RegisterUserHandler(std::shared_ptr<HttpConnection> conn);
    void ResetPasswordHandler(std::shared_ptr<HttpConnection> conn);
    //用户登录处理的回调
    void LoginUserHandler(std::shared_ptr<HttpConnection> conn);


private:
    std::map<std::string,HttpHandler> post_handlers_;
    std::map<std::string,HttpHandler> get_handlers_;

};

